//
//  NetWrokInfoVC.m
//  AILock
//
//  Created by 谭亚明 on 2020/7/13.
//  Copyright © 2020 tym. All rights reserved.
//

#import "NetWrokInfoVC.h"
#import "EquipmentService.h"
#import "EquipmentModel.h"
@interface NetWrokInfoVC ()


@property(nonatomic,strong) EquipmentService *equipSer;
@property(nonatomic,strong) EquipmentModel *equModel;

@property(nonatomic,weak) IBOutlet UILabel *nameLab;
@property(nonatomic,weak) IBOutlet UIImageView *xinhaoImage;
@property(nonatomic,weak) IBOutlet UILabel *ipLab;
@property(nonatomic,weak) IBOutlet UILabel *macLab;
@end

@implementation NetWrokInfoVC

-(instancetype)initWithEquipmentModel:(EquipmentModel*)model{
    self = [super init];
    if (self) {
        self.equModel = model;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self addBackBtnFunc];
    [self addTitle:@"网络信息"];
    [self getEquipmentDetail];
    
}

-(void)getEquipmentDetail{
    TYMWeak(self);
    [self.equipSer getEquipmentinfo:self.equModel.equipmentId completion:^(NSError * _Nonnull error, EquipmentModel * _Nonnull equipmentModel) {
        weakself.equModel = equipmentModel;
        [weakself updateView];
    }];
}

-(EquipmentService*)equipSer{
    if (_equipSer == nil) {
        _equipSer = [[EquipmentService alloc] init];
    }
    return _equipSer;
}

-(void)updateView{
    self.nameLab.text = self.equModel.wifiName;
    self.ipLab.text = self.equModel.ipAddress;
    self.macLab.text = self.equModel.macAddress;
    
    self.xinhaoImage.image = [UIImage imageNamed:[self wiftBtnImage:self.equModel.wifiStrength]];
   // self.xinhaoLab.text = self.equModel.
}

-(NSString*)wiftBtnImage:(NSInteger)wifiValue{
    if (!wifiValue) {
        return @"icon_equipment103";
    }else if(wifiValue < 5){
       return @"icon_equipment102";
    }else if(wifiValue < 20){
         return @"icon_equipment104";
    }else if(wifiValue < 30){
        return @"icon_equipment100";
    }else if(wifiValue < 50){
        return @"icon_equipment101";
    }
    return @"icon_equipment11";
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
